<?php 
class category_models_show extends CI_Model{
	public function __construct(){
		$this->load->database();
	}
	
	public function show($id,$page=0,$limit=25){
		$offset=$page*$limit;
		
		//$query = $this->db->get_where('category', array('id' => $id), $limit, $offset);
		$query= $this->db->select('prd_id')->
		from('product')->
		where(array('prd_active'=>1))->
		where("category_id in (select id from category where (parent= $id or id=$id )and active=1 )")->
		limit( $limit, $offset)->
		get();
		$product=array();
		if($query->num_rows()){
			foreach ( $query->result() as $row)
				$product[]=$row->prd_id;
		}
		return $product;
	}

	
	public function get_TopAnnonce($id,$limit=5){
		$query= $this->db->select('prd_id')->
		from('product')->
		where(array('prd_active'=>1,'top'=>1))->
		where("category_id in (select id from category where (parent= $id or id=$id )and active=1 )")->
		limit( $limit)->
		order_by('priority_date', 'RANDOM')->
		get();
		
		$product=array();
		if($query->num_rows()){
			foreach ( $query->result() as $row)
				$product[]=$row->prd_id;
		}
		return $product;
	}
	public function  total_annonces($id){
		$get= $this->db->select('count(*) as total')->
		from('product')->
		where(array('prd_active'=>1))->
		where("category_id in (select id from category where (parent= $id or id=$id )and active=1 )")->
		get();
		$row=$get->result();
		return $row[0];
	
	}
	public function  get_keywords($id){
		$this->db->select('*')->
		from('category')->
		where(array('parent'=>$id,'active'=>1))->
		or_where(array('id'=>$id))->
		order_by('order');
		$get= $this->db->get();
		$cat=array();
		foreach ($get->result() as $row)
			$cat[$row->id]=$row->keywords;
		return $cat;
	}
	public function  is_rencontres($category_id,$catShowModal=81){
		$this->db->select('*')->
		from('category')->
		where(array('id'=>$category_id))->
		where("(parent=$catShowModal OR id= $catShowModal)");

		$query= $this->db->get();
		if($query->num_rows()) return true;
		return false;
	}
}